# -*- coding:utf-8 -*-
# @Desc: 
# @Author: Administrator
# @DateTime: 2020/10/15 10:53


### 示例: 假设你获取到了2017年内地电影票房前20的电影(列表x)和电影票房数据(列表y),那么如何更加直观的展示该数据?

from matplotlib import pyplot, font_manager
import matplotlib

## 设置中文显示
matplotlib.rc('font', family='MicroSoft YaHei')
# my_font = font_manager.FontProperties(fname=r"c:\windows\fonts\simsun.ttc", weight='bold')

## 票房前20的电影名称(即y轴数据)
# x = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5\n：最后的骑士","摔跤吧！爸爸","加勒比海盗5\n：死无对证","金刚\n：骷髅岛","极限特工\n：终极回归","生化危机6\n：终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3\n：殊死一战","蜘蛛侠\n：英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",]
x = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5：最后的骑士","摔跤吧！爸爸","加勒比海盗5：死无对证","金刚：骷髅岛","极限特工：终极回归","生化危机6：终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3：殊死一战","蜘蛛侠：英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",]
## 票房前20的电影数据(即y轴数据),单位:亿
y = [56.01,26.94,17.53,16.49,15.45,12.96,11.8,11.61,11.28,11.12,10.49,10.3,8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23]

## 设置图形大小与清晰度
pyplot.figure(figsize=(20,8), dpi=80)

## 绘制条形图(横状)
# 注: 因为不能使用字符串,所以使用可迭代的数字数据
# 参数height设置条形高度,参数color设置条形颜色
pyplot.barh(range(len(x)), y, height=0.3, color='orange')

## 设置y轴刻度间距,字符串,中文显示,显示旋转角度
pyplot.yticks(range(len(x)), x)

## 设置网格,alpha设置网格线透明度
pyplot.grid(alpha=0.3)

## 展示条形图
pyplot.show()